package com.ljs.springbootinit.manager;

import com.ljs.springbootinit.common.ErrorCode;
import com.ljs.springbootinit.exception.BusinessException;
import com.yupi.yucongming.dev.client.YuCongMingClient;
import com.yupi.yucongming.dev.common.BaseResponse;
import com.yupi.yucongming.dev.model.DevChatRequest;
import com.yupi.yucongming.dev.model.DevChatResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 使用第三方库连接aI
 */
@Service
public class AiManage {

    @Resource
    private YuCongMingClient yuCongMingClient;
    DevChatRequest devChatRequest = new DevChatRequest();

    /**
     * Ai对话
     *
     * @param message 生成的信息
     * @param modelId 鱼聪明Ai的id
     * @return
     */
    public String doChat(Long modelId,String message ) {

        devChatRequest.setMessage(message);
        devChatRequest.setModelId(modelId);
        BaseResponse<DevChatResponse> response = yuCongMingClient.doChat(devChatRequest);
        if(response==null){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"AI响应错误");
        }
        return response.getData().getContent();
    }
}
